﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CommonListPage.aspx.cs" ValidateRequest="false" Inherits="XYTXL.View.CommonListPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <link href="/View/CSS/bootstrap3.3.5/css/bootstrap.css" rel="stylesheet" />
    <link rel="stylesheet" href="/View/JS/BootstrapTable/bootstrap-table.css" />
</head>
<body>
    <form id="form1" runat="server">
        <div class="container-fluid maindiv" style="margin-top: 20px" id="dvContent">
            <asp:PlaceHolder runat="server" ID="QueryCon" />


            <!-- Default panel contents -->

            <!-- Table -->
            <table id="FTGrid">
            </table>


            <input type="hidden" id="tabledata" value="" runat="server" />
            <input type="hidden" id="hidselID" value="" runat="server" />
            <input type="hidden" id="hidUserName" value="" runat="server" />
            <input type="hidden" id="hidCRUser" value="" runat="server" />
            <input type="hidden" id="hidQueryWhere" value="" runat="server" />
        </div>
    </form>
    <script type="text/javascript" src="/View/JS/jquery-1.11.2.min.js"></script>

    <script type="text/javascript" src="/View/CSS/bootstrap3.3.5/js/bootstrap.js"></script>
    <script type="text/javascript" src="/View/JS/json2.js"></script>
    <script type="text/javascript" src="/View/JS/BootstrapTable/bootstrap-table.js"></script>
    <script type="text/javascript" src="/View/JS/BootstrapTable/locale/bootstrap-table-zh-CN.js"></script>

    <script type="text/javascript" src="/View/JS/YanTip/YanTip.js"></script>
    <script type="text/javascript" src="/View/JS/FTCommon.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {

            if ($(".form_date")[0]) {
                $(".form_date").datetimepicker({
                    format: "yyyy-mm-dd"
                });
            }
            var tabledata = $("#tabledata").val();
            var FormCode = ComFunJS.getQueryString("FormCode");
            var MenuCode = ComFunJS.getQueryString("MenuCode");
            var jspath = "/View/JSList/" + FormCode + ".js";
            $.getJSON("/View/Base/AdminHandle.ashx", { Action: "GetMenuBtData", UserCode: parent.$("#hidUserName").val(), MenuCode: MenuCode }, function (data) {
                if (data) {
                    InitQX(data, FormCode, $("#hidselID"));
                }
            });

            $.getScript(jspath, function () {

                //加入chack列
                option.columns.unshift({
                    field: 'Table_Check',
                    checkbox: true
                })
                $("#FTGrid").bootstrapTable({
                    singleSelect: true,
                    checkboxHeader: false,
                    clickToSelect: true,
                    striped: true,
                    pagination: true,
                   // sidePagination: 'server',
                    pageSize: 10,
                    pageList: [10, 50, 100],
                    columns: option.columns,
                    onCheck: function (row) {
                        if (true) {
                            //单选
                            $("#hidselID").val(row.ID);
                            $("#hidUserName").val(row.CRUser);
                        } else {
                            //多选
                            var selrow = $('#FTGrid').bootstrapTable("getSelections");
                            var selids = "";
                            for (var i = 0; i < selrow.length; i++) {
                                selids = selids + selrow[i].ID + ",";
                            }
                            if (selids.length > 1) {
                                selids = selids.substring(0, selids.length - 1);
                            }
                            $("#hidselID").val(selids);
                        }
                    },
                    onUncheck: function (row) {
                        if (true) {
                            //单选
                            $("#hidselID").val("");

                        } else {
                            var selrow = $('#FTGrid').bootstrapTable("getSelections");
                            var selids = "";
                            for (var i = 0; i < selrow.length; i++) {
                                selids = selids + selrow[i].ID + ",";
                            }
                            if (selids.length > 1) {
                                selids = selids.substring(0, selids.length - 1);
                            }
                            $("#hidselID").val(selids);
                        }

                    },
                    queryParams: function (params) {
                        console.debug(params)
                        return {
                            pageSize: params.limit,
                            pageNum: Math.ceil((params.offset * 1 + 1 * 1) / params.limit),
                            sortOrder: params.order,
                            Search: $('.tbSearch').val()
                        }
                    },
                    data: jQuery.parseJSON(tabledata)

                    //url: '/API/VIEWAPI.ashx?Action=Commanage_GETXY'
                });
            });



        });
        function getseldata() {
            var selrow = $('#FTGrid').bootstrapTable("getSelections");
            return selrow;
        }
        function getselids() {
            return $("#hidselID").val();
        }
        //初始化List页面权限
        function InitQX(qxdata, FormCode, $FormDom) {

            var $btADD = $('<a href="#" class="btn btn-default addForm" type="button" >新   增</a>');
            var $btEDIT = $('<a href="#" class="btn btn-info EditForm" type="button" style=" margin-left: 20px" >编   辑</a>');
            var $btDEL = $('<a href="#" class="btn btn-danger DelForm" type="button" style="margin-left: 20px" >删   除</a>');
            var $btIMPORT = $('<a href="#" class="btn btn-danger ImportForm" type="button" style=" margin-left: 20px" >导入Excel</a>');
            $btADD.bind('click', function () {
                parent.MyDialog.viewform("/View/Comon/CommonAdd.aspx?FormCode=" + FormCode + "&Type=" + ComFunJS.getQueryString("Type"), "添加数据", '1000');
            })
            $btEDIT.bind('click', function () {
                var userName = $("#hidUserName").val();
                var CRUser = $("#hidCRUser").val();
                if ($FormDom.val() != "") {
                    if (FormCode == "SYJXDW") {
                        if (userName == CRUser) {
                            parent.MyDialog.viewform("/View/Comon/CommonUpdate.aspx?FormCode=" + FormCode + "&FormID=" + $FormDom.val(), "编辑数据", '1000')
                        } else {
                            parent.MyDialog.warning("您没有修改此数据的权限");
                        }
                    } else {

                        parent.MyDialog.viewform("/View/Comon/CommonUpdate.aspx?FormCode=" + FormCode + "&FormID=" + $FormDom.val(), "编辑数据", '1000')
                    }
                }

                else {
                    parent.MyDialog.warning("请先选择一条记录");
                }
            })
            $btDEL.bind('click', function () {
                if ($FormDom.val() == "") {
                    parent.MyDialog.warning("请先选择一条记录");
                } else {
                    parent.MyDialog.confirm('你确认要删除此条记录吗?', function () {
                        $.get(ComFunJS.getRootPath() + "/Comon/ComAjaxHandler.ashx", { Action: "DelFormData", FormCode: FormCode, FormID: $FormDom.val() }, function (data) {
                            if (data == "success") {
                                parent.MyDialog.success("删除成功");
                                var ids = [];
                                $.each($FormDom.val().split(","), function (i, n) {
                                    ids.push(n * 1);//转为数字数组
                                });
                                $("#FTGrid").bootstrapTable('remove', {
                                    field: 'ID',
                                    values: ids
                                });
                            }
                            else {
                                parent.MyDialog.warning("删除失败");

                            }
                        });
                    })

                }
            })
            $btIMPORT.bind('click', function () {
                parent.MyDialog.btnwin('/View/UCMangForm/SBExport.aspx', 700, 550, {}, function (layero, index) {
                    var frameid = $("iframe", $(layero)).attr('id');
                    var drtaskdata = parent.window.frames[frameid].model.DataList.$model;
                    for (var i = 0; i < drtaskdata.length; i++) {
                        var item = {};
                        item.tasksdate = drtaskdata[i].任务开始时间;
                        item.zxname = $("#myTab li.active").find(".sptabname").text();
                        item.taskdate = drtaskdata[i].任务结束时间
                        item.taskname = drtaskdata[i].任务内容;
                        item.taskpeoples = drtaskdata[i].usercode;
                        item.alltasks = [];
                        var arrpeople = item.taskpeoples.split(",");
                        for (var m = 0; m < arrpeople.length ; m++) {
                            item.alltasks.push({ taskpeople: arrpeople[m], taskstatus: "", taskwcdate: "", taskremark: "" })
                        }
                        if (!elem) {
                            if (drtaskdata[i].usercode != "暂无人员") {
                                vm.taskdata.push(item);
                                vm.taskdata.sort(vm.sortDate);
                            }
                        }
                        if (item.taskname === "") {
                            vm.taskdata.remove(item);
                        }

                    }
                    parent.layer.close(index)
                });
            })
            for (var i = 0; i < qxdata.length; i++) {
                if (qxdata[i].AuthName == "ADD") {
                    $(".FT_dvbtn").append($btADD)
                }
                if (qxdata[i].AuthName == "EDIT") {
                    $(".FT_dvbtn").append($btEDIT)
                }
                if (qxdata[i].AuthName == "DEL") {
                    $(".FT_dvbtn").append($btDEL)
                }

                if (qxdata[i].AuthName == "EXPORT") {
                    $("#btExport").show();
                }
                if (qxdata[i].AuthName == "IMPORT") {
                    $("#btImport").show();
                }
            }
        }
    </script>
</body>
</html>

